//时间格式化
const formatTime = date => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-')
}


// 格式化数字
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

//封装的 showToast
//title: res.msg,icon: 'success',duration: 1500
const _showToast = (title, icon = 'none', duration = 1500) => {
  wx.showToast({
    title: title, //返回的提升信息
    icon: icon, //显示图标
    duration: duration //加载时间
  });
}

//页面跳转
const _navigateTo = (url) => {
  wx.navigateTo({
    url
  })
}

//跨page跳转
const _switchTab = (url) => {
  wx.switchTab({
    url
  })
}


module.exports = {
  formatTime,
  _showToast,
  _navigateTo,
  _switchTab
}